package com.dl.chat.synctask;


import jakarta.annotation.PreDestroy;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

@Component
public class ShutdownHook {

    @Resource
    private ChatHistorySyncTask chatHistorySyncTask;

    /**
     * 服务关闭时同步 Redis 数据到 PostgreSQL
     */
    @PreDestroy
    public void onShutdown() {
        System.out.println("服务关闭：开始同步 Redis 数据到 PostgreSQL");
        chatHistorySyncTask.syncChatHistory();
        System.out.println("服务关闭：Redis 数据已同步到 PostgreSQL");
    }
}